package com.cn.redis;


import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.lang.Nullable;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocketFactory;
import java.time.Duration;
import java.util.Optional;

public class DistributedJedisClientConfiguration implements JedisClientConfiguration {
    private final boolean useSsl = false;
    private final Optional<SSLSocketFactory> sslSocketFactory = Optional.ofNullable((SSLSocketFactory)null);
    private final Optional<SSLParameters> sslParameters = Optional.ofNullable((SSLParameters)null);
    private final Optional<HostnameVerifier> hostnameVerifier = Optional.ofNullable((HostnameVerifier)null);
    private final boolean usePooling;
    private final Optional<GenericObjectPoolConfig> poolConfig;
    private final Optional<String> clientName;
    private Duration readTimeout = Duration.ofMillis(2000L);
    private Duration connectTimeout = Duration.ofMillis(2000L);

    public DistributedJedisClientConfiguration(boolean usePooling, @Nullable GenericObjectPoolConfig poolConfig, @Nullable String clientName) {
        this.usePooling = usePooling;
        this.poolConfig = Optional.ofNullable(poolConfig);
        this.clientName = Optional.ofNullable(clientName);
    }

    public boolean isUseSsl() {
        return false;
    }

    public Optional<SSLSocketFactory> getSslSocketFactory() {
        return this.sslSocketFactory;
    }

    public Optional<SSLParameters> getSslParameters() {
        return this.sslParameters;
    }

    public Optional<HostnameVerifier> getHostnameVerifier() {
        return this.hostnameVerifier;
    }

    public boolean isUsePooling() {
        return this.usePooling;
    }

    public Optional<GenericObjectPoolConfig> getPoolConfig() {
        return this.poolConfig;
    }

    public Optional<String> getClientName() {
        return this.clientName;
    }

    public Duration getReadTimeout() {
        return this.readTimeout;
    }

    public void setReadTimeout(int readTimeout) {
        this.readTimeout = Duration.ofMillis((long)readTimeout);
    }

    public void setConnectTimeout(int connectTimeout) {
        this.connectTimeout = Duration.ofMillis((long)connectTimeout);
    }

    public Duration getConnectTimeout() {
        return this.connectTimeout;
    }
}
